package awk.reflect.subclass;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

public class _Concat_Ws implements UdfFunction{

    public String concat(String comma, List<Object> param) {
        if (StringUtils.isEmpty(comma)){
            comma = ",";
        }

        List<String> result = new ArrayList<>();
        param.parallelStream().forEach(s->{
            if (s instanceof Collection){
                Collection set =(Collection)s;
                for (Object o : set) {
                    result.add(String.valueOf(o));
                }
            }else {
                result.add(String.valueOf(s));
            }
        });
        return result.stream().collect(Collectors.joining(comma));
    }

}
